/*
 * @Description: file content
 * @Author: Zt2tzzt
 * @Date: 2021-09-28 15:58:30
 * @LastEditors: Zt2tzzt
 * @LastEditTime: 2021-09-28 16:38:48
 * @LastEditContent: 
 */
var names = ['jesse', 'lionel', 'cristianol']

class Person {
  constructor(name, age) {
    this.name = name
    this.age = age
    this._address - '广州市'
  }

  // 普通的实例方法
  // 创建出来的对象进行访问
  // var p = new Person()
  // p.eating()
  eating() {
    console.log(this.name, 'eating')
  }
  running() {
    console.log(this.name, 'running')
  }
  
  // 类的访问器方法
  get address() {
    console.log('拦截访问操作')
    return this._address
  }
  set address(newAddress) {
    console.log('拦截设置操作')
    this._address = newAddress
  }

  // 类的静态方法（类方法）
  // Person.createPerson()
  static rendomPerson() {
    var nameIndex = Math.floor(Math.random() * names.length)
    var name = names[nameIndex]
    var age = Math.floor(Math.random() * 100)
    return new Person(name, age)
  }
}

var p = new Person('zzt', 18)
p.eating()
p.running()

console.log(p.address)
p.address = '北京市'
console.log(p.address)

for(var i=0; i<50; i++) {
  console.log(Person.rendomPerson())
}
